home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / mail / pathalia.zoo / src / def.h < prev    next >
C/C++ Source or Header  |  1991-01-12  |  5KB  |  159 lines

  1. /* pathalias -- by steve bellovin, as told to peter honeyman */
  2.  
  3. #ifndef lint
  4. #ifdef MAIN
  5. static char    *h_sccsid = "@(#)def.h    9.5 88/05/09";
  6. #endif /*MAIN*/
  7. #endif /*lint*/
  8.  
  9. #include <stdio.h>
  10. #include <ctype.h>
  11. #include "config.h"
  12.  
  13. typedef    long Cost;
  14. typedef struct node node;
  15. typedef struct link link;
  16.  
  17. #ifdef lint
  18. #define vprintf fprintf
  19. #else /*!lint -- this gives null effect warning*/
  20. /* because it's there ... */
  21. #define vprintf        !Vflag ? 0 : fprintf
  22. #endif /*lint*/
  23.  
  24. #define NTRACE    16    /* can trace up to NTRACE hosts/links */
  25.  
  26. /* flags for n_flag */
  27. #define ISPRIVATE  0x0001 /* invisible outside its definition file */
  28. #define NALIAS       0x0002 /* heaped as an alias */
  29. #define ATSIGN       0x0004 /* seen an at sign?  used for magic @/% rules */
  30. #define MAPPED       0x0008 /* extracted from heap */
  31. #define    NDEAD       0x0010 /* out links are dead */
  32. #define HASLEFT       0x0020 /* has a left side net character */
  33. #define HASRIGHT   0x0040 /* route has a right side net character */
  34. #define    NNET       0x0080 /* network pseudo-host */
  35. #define INDFS       0x0100 /* used when removing net cycles (for -g) */
  36. #define DUMP       0x0200 /* we have dumped this net's edges (for -g) */
  37. #define PRINTED       0x0400 /* this host has been printed */
  38. #define NTERMINAL  0x0800 /* heaped as terminal edge (or alias thereto) */
  39. #define NREF       0x1000 /* node has an "interesting" reference */
  40.  
  41. #define ISADOMAIN(n)     ((n)->n_name[0] == '.')
  42. #define ISANET(n)     (((n)->n_flag & NNET) || ISADOMAIN(n))
  43. #define ALTEREGO(n1, n2) ((n1)->n_name == (n2)->n_name)
  44. #define DEADHOST(n)     (((n)->n_flag & (NDEAD | NTERMINAL)) && !ISANET(n))
  45. #define DEADLINK(l)     ((l)->l_flag & LDEAD)
  46. #define DEADNET(n)     (((n)->n_flag & (NNET | NDEAD)) == (NNET | NDEAD))
  47. #define GATEWAYED(n)     (DEADNET(n) || ISADOMAIN(n))
  48.  
  49. #ifndef DEBUG
  50. /*
  51.  * save some space in nodes -- there are > 10,000 allocated!
  52.  */
  53.  
  54. #define n_root un1.nu_root
  55. #define n_net un1.nu_net
  56. #define n_copy un1.nu_copy
  57.  
  58. #define n_private un2.nu_priv
  59. #define n_parent  un2.nu_par
  60.  
  61. /* WARNING: if > 2^16 nodes, type of n_tloc must change */
  62. struct node {
  63.     char    *n_name;    /* host name */
  64.     link    *n_link;    /* adjacency list */
  65.     Cost    n_cost;        /* cost to this host */
  66.     union {
  67.         node *nu_net;    /* others in this network (parsing) */
  68.         node *nu_root;    /* root of net cycle (graph dumping) */
  69.         node *nu_copy;    /* circular copy list (mapping) */
  70.     } un1;
  71.     union {
  72.         node *nu_priv;    /* other privates in this file (parsing) */
  73.         node *nu_par;    /* parent in shortest path tree (mapping) */
  74.     } un2;
  75.     unsigned short n_tloc;    /* back ptr to heap/hash table */
  76.     unsigned short n_flag;        /* see manifests above */
  77. };
  78.  
  79. #endif /*DEBUG*/
  80.  
  81. #define MILLION (1000L * 1000L)
  82. #define    DEFNET    '!'            /* default network operator */
  83. #define    DEFDIR    LLEFT            /* host on left is default */
  84. #define    DEFCOST    ((Cost) 4000)        /* default cost of a link */
  85. #define    INF    ((Cost) 100 * MILLION)    /* infinitely expensive link */
  86. #define DEFPENALTY ((Cost) 200)        /* default avoidance cost */
  87. #ifndef ATARI
  88. #define NULL_FILE "/dev/null"
  89. #else
  90. #define NULL_FILE "con:"
  91. #endif
  92.  
  93. /* data structure for adjacency list representation */
  94.  
  95. /* flags for l_dir */
  96.  
  97. #define NETDIR(l)    ((l)->l_flag & LDIR)
  98. #define NETCHAR(l)    ((l)->l_netop)
  99.  
  100. #define LDIR      0x0008    /* 0 for left, 1 for right */
  101. #define LRIGHT      0x0000    /* user@host style */
  102. #define LLEFT      0x0008    /* host!user style */
  103.  
  104. #define LDEAD      0x0010    /* this link is dead */
  105. #define LALIAS      0x0020    /* this link is an alias */
  106. #define LTREE      0x0040    /* member of shortest path tree */
  107. #define LGATEWAY  0x0080    /* this link is a gateway */
  108. #define LTERMINAL 0x0100    /* this link is terminal */
  109.  
  110. #ifndef DEBUG
  111. /*
  112.  * borrow a field for link/node tracing.  there's a shitload of
  113.  * edges -- every word counts.  only so much squishing is possible:
  114.  * alignment dictates that the size be a multiple of four.
  115.  */
  116.  
  117. #define l_next un.lu_next
  118. #define l_from un.lu_from
  119.  
  120. struct link {
  121.     node    *l_to;        /* adjacent node */
  122.     Cost    l_cost;        /* edge cost */
  123.     union {
  124.         link *lu_next;    /* rest of adjacency list (not tracing) */
  125.         node *lu_from;    /* source node (tracing) */
  126.     } un;
  127.     short    l_flag;        /* right/left syntax, flags */
  128.     char    l_netop;    /* network operator */
  129. };
  130.  
  131. #endif /*DEBUG*/
  132.  
  133. #ifdef DEBUG
  134. /*
  135.  * flattening out the unions makes it easier
  136.  * to debug (when pi is unavailable).
  137.  */
  138. struct node {
  139.     char    *n_name;
  140.     link    *n_link;
  141.     Cost    n_cost;
  142.     node    *n_net;
  143.     node    *n_root;
  144.     node    *n_copy;
  145.     node    *n_private;
  146.     node    *n_parent;
  147.     unsigned short n_tloc;
  148.     unsigned short n_flag;
  149. };
  150. struct link {
  151.     node    *l_to;
  152.     Cost    l_cost;
  153.     link    *l_next;
  154.     node    *l_from;
  155.     short    l_flag;
  156.     char    l_netop;
  157. };
  158. #endif /*DEBUG*/
  159.